package LeetCode;

import java.util.Stack;

/**
 * 剑指 Offer 09. 用两个栈实现队列
 * 说明：请实现它的两个函数 appendTail 和 deleteHead ，分别完成在队列尾部插入整数和在队列头部删除整数的功能。(若队列中没有元素，deleteHead操作返回 -1 )
 *
 * 来源：力扣（LeetCode）
 * 链接：https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof
 */
public class Offer09 {
    private Stack<Integer> stack1 = new Stack<>();
    private Stack<Integer> stack2 = new Stack<>();

    public Offer09() {
    }

    public void appendTail(int value) {
        while(!stack2.isEmpty()){
            stack1.push(stack2.pop());
        }
        stack1.push(value);
    }

    public int deleteHead() {
        while (!stack1.isEmpty()){
            stack2.push(stack1.pop());
        }

        return stack2.isEmpty()? -1:stack2.pop();
    }

    public static void main(String[] args) {
        Offer09 offer09 = new Offer09();
        offer09.appendTail(3);
        System.out.println(offer09.deleteHead());
        System.out.println(offer09.deleteHead());
    }
}
